﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL
{
    public class RegistrationBll
    {
        DAL.RegistrationDal regDal = new DAL.RegistrationDal();

        public bool AddRegistration(Model.Registration reg)
        {
            return regDal.AddRegistration(reg);
        }

        public DataTable GetAllRegistration()
        {
            return regDal.GetRegistrationAll();
        }

        public Model.Registration GetRegistrationById(int regId)
        {
            DataTable table = regDal.GetRegistrationById(regId);
            Model.Registration reg = new Model.Registration();

            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["proId"] != null && table.Rows[0]["proId"].ToString() != "")
                {
                    reg.proId = table.Rows[0]["proId"].ToString();
                }
                if (table.Rows[0]["proName"] != null && table.Rows[0]["proName"].ToString() != "")
                {
                    reg.proName = table.Rows[0]["proName"].ToString();
                }
                if (table.Rows[0]["regAccount"] != null && table.Rows[0]["regAccount"].ToString() != "")
                {
                    reg.regAccount = table.Rows[0]["regAccount"].ToString();
                }
                if (table.Rows[0]["regAddress"] != null && table.Rows[0]["regAddress"].ToString() != "")
                {
                    reg.regAddress = table.Rows[0]["regAddress"].ToString();
                }
                if (table.Rows[0]["regBirthday"] != null && table.Rows[0]["regBirthday"].ToString() != "")
                {
                    reg.regBirthday = table.Rows[0]["regBirthday"].ToString();
                }
                if (table.Rows[0]["regDegree"] != null && table.Rows[0]["regDegree"].ToString() != "")
                {
                    reg.regDegree = table.Rows[0]["regDegree"].ToString();
                }
                if (table.Rows[0]["regId"] != null && table.Rows[0]["regId"].ToString() != "")
                {
                    reg.regId = int.Parse(table.Rows[0]["regId"].ToString());
                }
                if (table.Rows[0]["regIDCard"] != null && table.Rows[0]["regIDCard"].ToString() != "")
                {
                    reg.regIDCard = table.Rows[0]["regIDCard"].ToString();
                }
                if (table.Rows[0]["regMail"] != null && table.Rows[0]["regMail"].ToString() != "")
                {
                    reg.regMail = table.Rows[0]["regMail"].ToString();
                }
                if (table.Rows[0]["regName"] != null && table.Rows[0]["regName"].ToString() != "")
                {
                    reg.regName = table.Rows[0]["regName"].ToString();
                }
                if (table.Rows[0]["regNative"] != null && table.Rows[0]["regNative"].ToString() != "")
                {
                    reg.regNative = table.Rows[0]["regNative"].ToString();
                }
                if (table.Rows[0]["regPhone"] != null && table.Rows[0]["regPhone"].ToString() != "")
                {
                    reg.regPhone = table.Rows[0]["regPhone"].ToString();
                }
                if (table.Rows[0]["regSchool"] != null && table.Rows[0]["regSchool"].ToString() != "")
                {
                    reg.regSchool = table.Rows[0]["regSchool"].ToString();
                }
                if (table.Rows[0]["regSex"] != null && table.Rows[0]["regSex"].ToString() != "")
                {
                    reg.regSex = table.Rows[0]["regSex"].ToString();
                }
                if (table.Rows[0]["regZip"] != null && table.Rows[0]["regZip"].ToString() != "")
                {
                    reg.regZip = table.Rows[0]["regZip"].ToString();
                }
                return reg;
            }
            else
            {
                return null;
            }
        }

        public bool Luqu(string stuId, string password, string name, int regId)
        {
            return regDal.Luqu(stuId, password, name, regId);
        }
    }
}
